<template>
<div class="product-add">
    <!--form表单-->
    <el-form size="small" ref="form" :model="form" label-width="200px">
      <!--添加门店-->
      <div class="common-form">{{$t('setting.edit_logistics_company')}}</div>
      <el-form-item :label="$t('setting.logistics_company_name1')">
        <el-input v-model="form.expressName" class="max-w460"></el-input>
        <div class="tips"> {{$t('setting.reference_label')}} 

<el-link type="primary" :underline="false" @click="gotoCompany()">{{$t('setting.logistics_code_table_label')}}</el-link> {{$t('setting.fill_in_label')}} 

</div>
      </el-form-item>
      <el-form-item :label="$t('setting.logistics_company_code2')">
        <el-input v-model="form.expressCode" class="max-w460"></el-input>
        <div class="tips">{{$t('setting.logistics_code_tip')}}</div>
      </el-form-item>
      <el-form-item :label="$t('setting.wechat_logistics_code0')">
        <el-input v-model="form.wxCode" class="max-w460"></el-input>
        <div class="tips">{{$t('setting.reference_label')}} 
<el-link type="primary" :underline="false" @click="gotoWxCompany()"> {{$t('setting.wechat_logistics_code_table')}} 

</el-link> {{$t('setting.fill_in_label')}} 

</div>
        <div class="tips">{{$t('setting.wx_logistics_id_tip')}}</div>
      </el-form-item>
      <el-form-item prop="carrierId" :label="$t('setting.carrier')">
        <el-select
            v-model="form.carrierId"
            style="width: 460px"
            :placeholder="$t('setting.please_select')"
        >
          <el-option
              v-for="(item, index) in carrierList"
              :key="index"
              :label="item.logisticsCompany"
              :value="item.carrierId"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('setting.sort_order')">
        <el-input v-model="form.sort" type="number" class="max-w460"></el-input>
        <div class="tips">{{$t('setting.sort_order_tip')}}</div>
      </el-form-item>
      <!--提交-->
      <div class="common-button-wrapper"><el-button type="primary" @click="onSubmit" :loading="loading">{{$t('setting.submit_button')}}</el-button></div>
    </el-form>
  </div>
</template>

<script>
import SettingApi from '@/api/setting.js';
export default {
  data() {
    return {
      /*切换菜单*/
      // activeIndex: '1',
      /*form表单数据*/
      form: {
        expressId: '',
        expressName: '',
        expressCode: '',
        wxCode: '',
        sort: '',
        carrierId: ""
      },
      carrierList: [],
      loading: false
    };
  },
  created() {
    this.getData();
    this.getcarrier();
  },
  methods: {
    getcarrier() {
      SettingApi.expressAdd().then(res => {
        this.carrierList = res.data.carrier;
      });
    },
    /*获取数据*/
    getData() {
      let self = this;
      // 取到路由带过来的参数
      const params = this.$route.query.expressId;
      SettingApi.expressDetail({
        expressId: params
      }, true).then(res => {
        let detail = res.data;
        // 将数据放在当前组件的数据内
        self.form.expressId = detail.expressId;
        self.form.expressName = detail.expressName;
        self.form.expressCode = detail.expressCode;
        self.form.sort = detail.sort;
        self.form.carrierId = detail.carrierId;
        self.form.wxCode = detail.wxCode;
      }).catch(error => {});
    },
    /*提交表单*/
    onSubmit() {
      let self = this;
      self.loading = true;
      let params = this.form;
      SettingApi.editExpress(params, true).then(data => {
        self.loading = false;
        ElMessage({
          message: $t("setting.edit_success_message"),
          type: 'success'
        });
        self.$router.push('/setting/express/index');
      }).catch(error => {
        self.loading = false;
      });
    },
    /*跳转物流编码*/
    gotoCompany() {
      let baseUrl = window.location.protocol + '//' + window.location.host;
      window.location.href = baseUrl + '/express.xlsx';
    },
    /*跳转微信物流编码表*/
    gotoWxCompany() {
      //let baseUrl = window.location.protocol + '//' + window.location.host;
      //window.location.href = baseUrl + '/wx_express.xlsx';
      window.location.href = 'https://qn-cdn.jjjshop.net/20230918111831794.xlsx';
    }
  }
};
</script>

<style>
.tips {
  color: #ccc;
}
</style>

